"""
@project: PyCharm
@author: MZM
@file: testrunner.py
@ide: PyCharm
@time: 2021/6/30 10:12
@desc：
"""
import datetime
import os


import pytest

filepath = os.path.dirname(__file__)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def run():
    os.chdir(filepath)
    ts = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
    datadir = f'{filepath}/runner/allure_report/data{ts}'
    htmldir = f'{BASE_DIR}/data/testreport/html{ts}'
    testargs = []
    testargs.append(f'--rootdir={filepath}')
    testargs.append(f'--log-file={filepath}/pytest.log')
    testargs.append('--alluredir')
    testargs.append(datadir)
    testargs.append(f'{filepath}/test_script.py')
    pytest.main(testargs)
    os.system((f'allure generate {datadir} -o {htmldir} --clean'))
    return htmldir

if __name__ == '__main__':
    run()